<?php
defined('DCS_ROOT') or exit(header("HTTP/1.1 430 Not Forbidden"));

class profile {

	function __construct() {
		require_once(APP_PATH."Model/Member/Init.php" );
		$action = $url['action'];
		if($action == 'profile'){
			$this->defaultAction();
		}else{
			pageError();
		}
		exit();
	}

	function defaultAction(){		
		if(isPost()){
			$art['uid'] = addslashes(trim($_POST['uid']));
			$art['password'] = addslashes(trim($_POST['password']));
			$art['newpassword'] = addslashes(trim($_POST['newpassword']));
			$art['email'] = addslashes(trim($_POST['email']));
			$art['tel'] = addslashes(trim($_POST['tel']));
			$art['password'] = empty($art['newpassword']) ? $art['password'] : md5($art['newpassword']);
			if(!$art['tel']){
				message('请填写您的联系电话！');
			}
			$user = $this->user;
			if($art['uid'] != $user['uid']){
				message('无此权限');
			}

			require_once(APP_PATH."model/Member/User.php" );
			$DB  = getDB();
			$data = new User ($DB);			
			$edit = $data->editUser($art['uid'],$art['password'],$art['tel'],$art['email']);			
			if ($edit){
				$message = '成功修改个人信息';
			}else{
				$message = '修改个人信息失败';
			}
			message($message);
		}else{
			$DB = getDB();			
			$user = $this->user;
			require_once(APP_PATH."Model/Member/User.php" );
			$data = new User($DB);
			$userInfo = $data->getUserbasic($user['username']);
			$tpl = new Template('member/profile.htm');
			$tpl->assign($userInfo);		
			$tpl->assign(getMember());
			$tpl->output();
		}
    }
	
}
